package com.xt.website.dao;

import com.xt.website.po.Category;
import com.xt.website.po.CategoryExt;
import com.xt.website.po.CategorySecond;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.List;

/*
 * @Author 爱尚实训赵国鑫
 * @ClassName  CategoryDao
 * @Date 2019/8/18/9:09
 * @Description TODO:(一句话描述这个类)
 */
@Mapper
public interface CategoryDao {
    /**
     * 获取一二级类目集合
     *
     * @return List<CategoryExt>
     */
    @Select("select * from tb_category order by sort asc")
    @Results(id = "categoryMap", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "cname", property = "cname"),
            @Result(column = "image", property = "image"),
            @Result(column = "publicityOne", property = "publicityOne"),
            @Result(column = "publicityTwo", property = "publicityTwo"),
            @Result(column = "sort", property = "sort"),
            @Result(column = "type", property = "type"),
            @Result(column = "id", property = "list",
                    many = @Many(select = "com.xt.website.dao.CategoryDao.getCategorySecondsByCid"))
    })
    ArrayList<CategoryExt<CategorySecond>> getAllCategories();


    /**
     * 根据一级类目cid查询二级类目集合
     *
     * @param cid
     * @return
     */
    @Select("select * from tb_categorysecond where cid=#{cid} order by sort asc")
    ArrayList<CategorySecond> getCategorySecondsByCid(Integer cid);

    /**
     * 查询一级类目详情，并查询该类目下的全部二级类目
     */
    @Select("select * from tb_category where id = #{cid}")
    @ResultMap("categoryMap")
    CategoryExt<CategorySecond> findCategoryByCid(Integer cid);

    /**
     * 根据csid查询二级类目信息
     */
    @Select("select * from tb_categorysecond where id = #{csid}")
    CategorySecond findCategorySecondByCsid(Integer csid);

    /**
     * 获取一级类目集合
     */
    @Select("select * from tb_category order by sort asc")
    List<Category> getCategories();
}
